/*
 * @lc app=leetcode.cn id=559 lang=typescript
 *
 * [559] N 叉树的最大深度
 */

// @lc code=start
/**
 * Definition for Node.
 * class Node {
 *     val: number
 *     children: Node[]
 *     constructor(val?: number, children?: Node[]) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.children = (children===undefined ? [] : children)
 *     }
 * }
 */

function maxDepth(root: Node | null): number {
    if (!root) return 0;
    let deepCount = root.children.map((i) => {
        return maxDepth(i);
    });
    // TODO 要塞一个 0 垫底，max 这些里面为空时会 BUG
    const deepest = Math.max(0, ...deepCount);
    return deepest + 1;
}
// @lc code=end
